package fab.graphics 
{
	import flash.display.DisplayObject;
	import flash.geom.Rectangle;
	/**
	 * ...
	 * @author fab
	 */
	public class ImageUtils
	{
		static public function fit( photo:DisplayObject, rectangle:Rectangle ):void
		{
			var ratio_photo:Number = photo.width / photo.height;
			var ratio_rectangle:Number = rectangle.width / rectangle.height;
			if ( ratio_photo < ratio_rectangle )
			{
				photo.height = Math.min( rectangle.height, photo.height );
				photo.width = photo.height * ratio_photo;
			}
			else {
				photo.width = Math.min( rectangle.width, photo.width );
				photo.height = photo.width / ratio_photo;
			}
			photo.x = rectangle.left + rectangle.width / 2 - photo.width / 2;
			photo.y = rectangle.top + rectangle.height / 2 - photo.height / 2;
		}
		static public function overfit( photo:DisplayObject, rectangle:Rectangle ):void
		{trace(photo.width)
			var ratio_photo:Number = photo.width / photo.height;
			var ratio_rectangle:Number = rectangle.width / rectangle.height;
			if ( ratio_photo > ratio_rectangle )
			{
				photo.height = rectangle.height;
				photo.width = photo.height * ratio_photo;
			}
			else {
				photo.width = rectangle.width;
				photo.height = photo.width / ratio_photo;
			}
			photo.x = rectangle.left + rectangle.width / 2 - photo.width / 2;
			photo.y = rectangle.top + rectangle.height / 2 - photo.height / 2;
		}
		
	}

}